package net.cloudsun.graph.util;

import java.util.Arrays;

/**
 * 数组复制
 * created at 23/11/2021
 *
 * @author 俞建波
 * <a href="mailto://yujianbo@chtwm.com">yujianbo@chtwm.com</a>
 * @since 1.1.0
 */
public class ArrayUtils {

    public int[][] copy(int[][] source) {
        int[][] result = new int[source.length][];
        for (int i = 0; i < source.length; i++) {
            result[i] = Arrays.copyOf(source[i], source[i].length);
        }
        return result;
    }


    public static int[] joinArray(int[][] ints) {
        return Arrays.stream(ints).reduce(new int[0], (x, y) -> {
            if (x.length == 0) {
                return y;
            }
            int[] array = new int[x.length + y.length];
            System.arraycopy(x, 0, array, 0, x.length);
            System.arraycopy(y, 0, array, x.length, y.length);
            return array;
        });
    }
}
